package com.xunshangwang.pinhaohuo.adapters;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.xunshangwang.pinhaohuo.R;
import com.xunshangwang.pinhaohuo.entity.Pin;
import com.xunshangwang.pinhaohuo.tools.CommonTool;

import java.util.List;

import tool.library.adapter.BaseRecyclerAdapter;

/**
 * Created by xzp on 16/3/8.
 */
public class PinAdapter extends BaseRecyclerAdapter<Pin>{
    public PinAdapter(Context context) {
        super(context);
    }

    @Override
    public RecyclerView.ViewHolder onCreateHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(getContext()).inflate(R.layout.pin_item,parent,false);
        return new PinHolder(view);
    }

    @Override
    public void onBindHolder(RecyclerView.ViewHolder holder, int position) {
        PinHolder pinHolder= (PinHolder) holder;
        Pin pin=getList().get(position);
        Glide.with(getContext()).load(pin.getGoods_info().getImage_url()).centerCrop().into(pinHolder.goodsImage);
        pinHolder.nameText.setText(pin.getGoods_info().getGoods_name());
        pinHolder.openGroupTimeText.setText("开团" + pin.getGroup_count() + "次");
        pinHolder.groupNumText.setText(pin.getGroup_goods_count()+"个团正在进行中");
        pinHolder.priceText.setText(CommonTool.getPriceFormatString(getContext(),pin.getGoods_info(),1));
    }
    private class PinHolder extends ClickableViewHolder{
        ImageView goodsImage;
        TextView nameText,priceText,openGroupTimeText,groupNumText;
        public PinHolder(View itemView) {
            super(itemView);
            ImageView arrowIcon= (ImageView) itemView.findViewById(R.id.right_arrow_icon);
            arrowIcon.setColorFilter(Color.WHITE);
            goodsImage= (ImageView) itemView.findViewById(R.id.goods_image);
            nameText= (TextView) itemView.findViewById(R.id.goods_name_text);
            priceText= (TextView) itemView.findViewById(R.id.goods_price_text);
            openGroupTimeText= (TextView) itemView.findViewById(R.id.open_group_time_text);
            groupNumText= (TextView) itemView.findViewById(R.id.group_num_text);
        }
    }
}
